import json
from flask import jsonify, request
from src.model.read_models import *
from src.model.models import *
from app_db import db


# 用户信息
class OperaUser(object):
    @staticmethod
    def put(put_data, requst_json):
        put_data.id = int(requst_json.get('id'))
        put_data.email = requst_json.get('email') if requst_json.get('email') else put_data.email
        put_data.name = requst_json.get('name') if requst_json.get('name') else put_data.name
        put_data.password_hash = requst_json.get('password_hash') if requst_json.get('password_hash') \
            else put_data.password_hash
        put_data.role_id = requst_json.get('role_id') if requst_json.get('role_id') else put_data.role_id

        db.session.commit()
        return 'update success', 204

    @staticmethod
    def post(requst_json):
        email = requst_json.get('email')
        name = requst_json.get('name')
        password_hash = requst_json.get('password_hash')

        task = User(email=email, name=name, password_hash=password_hash)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201

    def post_and_put(self, request_json=None):
        if request_json is None:
            request_json = request.json
        if isinstance(request_json, str):
            request_json = json.loads(request_json)

        if not request_json:
            return 'Has no data: {}'.format(request_json), 400
        else:
            table_data = User.query.filter_by(id=int(request_json.get('id'))).first()
            if table_data:
                self.put(put_data=table_data, requst_json=request_json)
                return 'put success', 204
            else:
                self.post(requst_json=request_json)
                return 'post data success', 201


# 操作product
class OperaDimProduct(object):
    @staticmethod
    def get():
        table_info = DimProduct.query.join(User, User.id == DimProduct.owner_id).\
            add_columns(DimProduct.id, DimProduct.product_name, DimProduct.product_describe, DimProduct.owner_id,
                        User.name).\
            filter(DimProduct.is_valid == 1).all()
        if table_info:
            arr = [{
                'id': data.id,
                'product_name': data.product_name,
                'product_describe': data.product_describe,
                'owner_id': data.owner_id,
                'owner_name': data.name
            } for data in table_info]
            json_data = {
                'code': 200,
                'data': arr
            }
            return jsonify(json_data)

    @staticmethod
    def post(post_json):
        product_name = post_json.get('product_name')
        product_describe = post_json.get('product_describe')
        owner_id = post_json.get('owner_id')
        task = DimProduct(product_name=product_name, product_describe=product_describe, owner_id=owner_id,
                          is_valid=1)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201


# 数据库驱动增查
class OperaDimDbDriverType(object):
    """
    dim_db_driver_type
    """
    @staticmethod
    def get():
        table_info = read_dim_db_driver_type()
        if table_info:
            json_data = {
                'code': 200,
                'data': table_info
            }
            return jsonify(json_data)

    @staticmethod
    def post(requst_json):
        db_driver_name = requst_json.get('db_driver_name')
        db_driver_describe = requst_json.get('db_driver_describe')
        owner_id = requst_json.get('owner_id')

        task = DimDbDriverType(db_driver_name=db_driver_name, db_driver_describe=db_driver_describe,
                               owner_id=owner_id)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201


# 数据类型增查
class OperaDataType(object):
    """
    dim_data_type
    """
    @staticmethod
    def get():
        table_info = read_dim_data_type()
        if table_info:
            json_data = {
                'code': 200,
                'data': table_info
            }
            return jsonify(json_data)

    @staticmethod
    def post(requst_json):
        data_type_name = requst_json.get('data_type_name')
        data_type_describe = requst_json.get('data_type_describe')
        db_driver_id = requst_json.get('db_driver_id')
        owner_id = requst_json.get('owner_id')

        task = DimDataType(data_type_name=data_type_name, data_type_describe=data_type_describe,
                           db_driver_id=db_driver_id, owner_id=owner_id)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201


# 数据库名称增删改查
class OperaDimDb(object):
    """
    dim db
    """
    @staticmethod
    def get():
        table_info = read_dim_db()
        if table_info:
            json_data = {
                'code': 200,
                'data': table_info
            }
            return jsonify(json_data)

    @staticmethod
    def put(put_data, requst_json):
        put_data.id = int(requst_json.get('id'))
        put_data.db_name = requst_json.get('db_name')
        put_data.db_describe = requst_json.get('db_describe')
        put_data.db_driver_id = requst_json.get('db_driver_id')
        put_data.product_id = requst_json.get('product_id')
        put_data.owner_id = requst_json.get('owner_id')
        put_data.is_valid = int(requst_json.get('is_valid'))

        db.session.commit()
        return 'update success', 204

    @staticmethod
    def post(requst_json):

        db_name = requst_json.get('db_name')
        db_describe = requst_json.get('db_describe')
        db_driver_id = requst_json.get('db_driver_id')
        product_id = requst_json.get('product_id')
        owner_id = requst_json.get('owner_id')

        task = DimDb(db_name=db_name, db_describe=db_describe, db_driver_id=db_driver_id, product_id=product_id,
                     owner_id=owner_id)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201

    def post_and_put(self, request_json=None):
        if request_json is None:
            request_json = request.json
        if isinstance(request_json, str):
            request_json = json.loads(request_json)

        if not request_json:
            return 'Has no data: {}'.format(request_json), 400
        else:
            table_data = DimDb.query.filter_by(id=int(request_json.get('id'))).first()
            if table_data:
                self.put(put_data=table_data, requst_json=request_json)
                return 'put success', 204
            else:
                self.post(requst_json=request_json)
                return 'post data success', 201


# 表的增删改查
class OperaDbTableRelate(object):
    """
    db_table_relate
    """
    @staticmethod
    def get(db_id):
        table_info = read_db_table_relate(db_id=db_id)
        json_data = {
            'code': 200,
            'data': table_info
        }
        return jsonify(json_data)

    @staticmethod
    def put(put_data, requst_json):
        put_data.id = int(requst_json.get('id'))
        put_data.db_id = int(requst_json.get('db_id'))
        put_data.table_name = requst_json.get('table_name')
        put_data.table_describe = requst_json.get('table_describe')
        put_data.save_path = requst_json.get('save_path')
        put_data.is_valid = int(requst_json.get('is_valid'))

        db.session.commit()
        return 'update success', 204

    @staticmethod
    def post(requst_json):
        db_id = int(requst_json.get('db_id'))
        table_name = requst_json.get('table_name')
        table_describe = requst_json.get('table_describe')
        table_info = requst_json.get('table_info')
        owner_id = requst_json.get('owner_id')

        task = DbTableRelate(db_id=db_id, table_name=table_name, table_describe=table_describe, table_info=table_info,
                             owner_id=owner_id)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201

    def post_and_put(self, request_json=None):
        if request_json is None:
            request_json = request.json
        if isinstance(request_json, str):
            request_json = json.loads(request_json)

        if not request_json:
            return 'Has no data: {}'.format(request_json), 400
        else:
            req_id = request_json.get('id')
            if req_id and req_id != 'None':
                table_data = DbTableRelate.query.filter_by(id=int(request_json.get('id'))).first()
                if table_data:
                    self.put(put_data=table_data, requst_json=request_json)
                    return 'put success', 204
                else:
                    self.post(requst_json=request_json)
                    return 'post data success', 201
            else:
                self.post(requst_json=request_json)
                return 'post data success', 201


# 字段增删改查
class OperaTableColumnRelate(object):
    """
    table_column_relate
    """
    @staticmethod
    def get(db_id, table_id):
        table_info = read_table_column_relate(db_id=int(db_id), table_id=int(table_id))
        json_data = {
            'code': 200,
            'data': table_info
        }
        return jsonify(json_data)

    @staticmethod
    def put(put_data, requst_json):
        put_data.id = int(requst_json.get('id'))
        put_data.db_id = int(requst_json.get('db_id'))
        put_data.table_id = int(requst_json.get('table_id'))
        put_data.column_name = requst_json.get('column_name')
        put_data.data_type_id = requst_json.get('data_type_id')
        put_data.column_describe = requst_json.get('column_describe')
        put_data.is_valid = int(requst_json.get('is_valid'))

        db.session.commit()
        return 'update success', 204

    @staticmethod
    def post(requst_json):
        db_id = int(requst_json.get('db_id'))
        table_id = int(requst_json.get('table_id'))
        column_id = requst_json.get('column_id')

        task = TableColumnRelate(db_id=db_id, table_id=table_id, column_id=column_id)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201

    def post_and_put(self, request_json=None):
        if request_json is None:
            request_json = request.json
        if isinstance(request_json, str):
            request_json = json.loads(request_json)

        if not request_json:
            return 'Has no data: {}'.format(request_json), 400
        else:
            req_id = request_json.get('id')
            if req_id and req_id != 'None':
                table_data = TableColumnRelate.query.filter_by(id=int(request_json.get('id'))).first()
                if table_data:
                    self.put(put_data=table_data, requst_json=request_json)
                    return 'put success', 204
                else:
                    self.post(requst_json=request_json)
                    return 'post data success', 201
            else:
                self.post(requst_json=request_json)
                return 'post data success', 201


# 操作 指标分类
class OperaColumnCategory(object):
    @staticmethod
    def get(category_name=None):
        query_info = DimColumnCategory.query.join(User, User.id == DimColumnCategory.owner_id). \
            add_columns(DimColumnCategory.id, DimColumnCategory.category_name, DimColumnCategory.owner_id,
                        User.name).\
            filter(DimColumnCategory.is_valid == 1)
        if category_name:
            query_info = query_info.filter(DimColumnCategory.category_name == category_name)

        table_info = query_info.all()
        if table_info:
            arr = [{
                'id': data.id,
                'category_name': data.category_name,
                'owner_id': data.owner_id,
                'owner_name': data.name
            } for data in table_info]

            json_data = {
                'code': 200,
                'data': arr
            }
            return jsonify(json_data)

    @staticmethod
    def post(post_json):
        category_name = post_json.get('category_name')
        owner_id = post_json.get('owner_id')

        task = DimColumnCategory(category_name=category_name, owner_id=owner_id, is_valid=1)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201


# 操作 标准指标
class OperaDimColumn(object):
    @staticmethod
    def jug_column_name(column_name, data_type_id):
        table_info = DimColumn.query.filter_by(column_name=column_name, data_type_id=data_type_id, is_valid=1).first()
        return True if table_info else False

    @staticmethod
    def get(category_id=None, type_id=None):
        base_query = DimColumn.query.join(DimColumnCategory, DimColumnCategory.id == DimColumn.category_id).\
            join(DimDataType, DimDataType.id == DimColumn.data_type_id). \
            join(User, User.id == DimColumn.owner_id). \
            add_columns(DimColumn.id, DimColumn.column_name, DimColumn.data_type_id, DimDataType.data_type_name,
                        DimColumn.data_length, DimColumn.column_describe, DimColumn.category_id,
                        DimColumnCategory.category_name, DimColumn.type_id, DimColumn.is_null, DimColumn.is_key,
                        DimColumn.defalut_value, DimColumn.owner_id, User.name).\
            filter(DimColumn.is_valid == 1)

        if category_id and not type_id:
            quer_info = base_query.filter(DimColumn.category_id == category_id)
        elif not category_id and type_id:
            quer_info = base_query.filter(DimColumn.type_id == type_id)
        elif category_id and type_id:
            quer_info = base_query.filter(DimColumn.type_id == type_id).filter(DimColumn.category_id == category_id)
        else:
            quer_info = base_query

        table_info = quer_info.all()
        if table_info:
            arr = [{
                'id': data.id,
                'column_name': data.column_name,
                'data_type_id': data.data_type_id,
                'data_type_name': data.data_type_name,
                'data_length': data.data_length,
                'column_describe': data.column_describe,
                'category_id': data.category_id,
                'category_name': data.category_name,
                'type_id': data.category_id,
                'type_name': '维度' if data.category_id == 1 else '度量',
                'is_null': '可空' if data.is_null is True else '不可空',
                'is_key': '主键' if data.is_key is True else '非主键',

                'is_null_id': data.is_null,
                'is_key_id': data.is_key,

                'defalut_value': data.defalut_value,

                'owner_id': data.owner_id,
                'owner_name': data.name
            } for data in table_info]
            json_data = {
                'code': 200,
                'data': arr
            }
            return jsonify(json_data)

    @staticmethod
    def post(post_json):
        column_name = post_json.get('column_name')
        data_type_id = post_json.get('data_type_id')
        data_length = post_json.get('data_length')
        column_describe = post_json.get('column_describe')
        category_id = post_json.get('category_id')
        type_id = post_json.get('type_id')

        is_null = post_json.get('is_null')
        is_key = post_json.get('is_key')
        defalut_value = post_json.get('defalut_value')

        owner_id = post_json.get('owner_id')

        task = DimColumn(column_name=column_name, data_type_id=data_type_id, data_length=data_length,
                         is_null=is_null, is_key=is_key, defalut_value=defalut_value,
                         column_describe=column_describe, category_id=category_id, type_id=type_id, owner_id=owner_id,
                         is_valid=1)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201

    @staticmethod
    def put(put_data, requst_json):
        put_data.id = requst_json.get('id')
        put_data.column_name = requst_json.get('column_name')
        put_data.data_type_id = requst_json.get('data_type_id')
        put_data.data_length = requst_json.get('data_length')
        put_data.column_describe = requst_json.get('column_describe')
        put_data.category_id = requst_json.get('category_id')
        put_data.type_id = requst_json.get('type_id')

        put_data.is_null = requst_json.get('is_null')
        put_data.is_key = requst_json.get('is_key')
        put_data.defalut_value = requst_json.get('defalut_value')

        put_data.owner_id = requst_json.get('owner_id')
        put_data.is_valid = requst_json.get('is_valid')

        db.session.commit()
        return 'update success', 204

    def post_and_put(self, request_json=None):
        if request_json is None:
            request_json = request.json
        if isinstance(request_json, str):
            request_json = json.loads(request_json)

        if not request_json:
            return 'Has no data: {}'.format(request_json), 400
        else:
            r_id = request_json.get('id')
            if r_id and r_id != 'None':
                table_data = DimColumn.query.filter_by(id=int(r_id)).first()
                if table_data:
                    self.put(put_data=table_data, requst_json=request_json)
                    return 'put success', 204
                else:
                    self.post(requst_json=request_json)
                    return 'post data success', 201
            else:
                self.post(requst_json=request_json)
                return 'post data success', 201


# 操作 sql
class OperaSql(object):
    @staticmethod
    def get(db_id, table_id):
        r = TableSQL.query.filter_by(db_id=db_id, table_id=table_id).first()
        return True if r else False

    @staticmethod
    def post(post_json):
        db_id = post_json.get('db_id')
        table_id = post_json.get('table_id')
        sql = post_json.get('sql')
        owner_id = post_json.get('owner_id')

        task = TableSQL(db_id=db_id, table_id=table_id, sql=sql, owner_id=owner_id)
        db.session.add(task)
        db.session.commit()
        return 'create success', 201


# create table sql
class CreateTableSQL(object):
    def __init__(self, table_id):
        self.table_query_info = DbTableRelate.query.join(DimDb, DimDb.id == DbTableRelate.db_id). \
            add_columns(DimDb.db_name, DbTableRelate.table_describe,
                        DbTableRelate.table_name, DbTableRelate.table_info). \
            filter(DbTableRelate.id == table_id).first()
        self.column_query_info = TableColumnRelate.query.join(DimColumn,
                                                              DimColumn.id == TableColumnRelate.column_id). \
            join(DimDataType, DimDataType.id == DimColumn.data_type_id). \
            add_columns(DimColumn.column_name, DimDataType.data_type_name, DimColumn.data_length,
                        DimColumn.column_describe, DimColumn.is_null, DimColumn.is_key, DimColumn.defalut_value). \
            filter(TableColumnRelate.table_id == table_id).all()
        self.db_name = self.table_query_info.db_name.upper()
        self.table_name = self.table_query_info.table_name.upper()
        self.table_name = self.table_query_info.table_name.upper()
        self.table_describe = self.table_query_info.table_describe
        self.table_info = self.table_query_info.table_info

    def read_hive(self):
        table_type = self.table_info.get('table_type')
        save_format = self.table_info.get('formatdata')
        save_path = self.table_info.get('save_path')
        line_terimial = self.table_info.get('line_terimial')
        fields_terimial = self.table_info.get('FIELDS_terimial')
        item_terimial = self.table_info.get('itemsplit')
        map_terminal = self.table_info.get('map_terimial')
        partition_attr = self.table_info.get('partition').upper()
        cluster_attr = self.table_info.get('cluster').upper()
        cluster_sort_attr = self.table_info.get('sorted').upper()
        cluster_nums = self.table_info.get('t_num')

        create_table_sql = 'DROP TABLE IF EXISTS {}.{};\n'.format(self.db_name, self.table_name)
        if table_type == '1':
            sql_str = 'CREATE TABLE IF NOT EXISTS {}.{}(\n'
        else:
            sql_str = 'CREATE EXTERNAL TABLE IF NOT EXISTS {}.{}(\n'
        sql_str = sql_str.format(self.db_name, self.table_name)
        # 字段
        # PRIMARY_KEY_str = ''
        for column_num, column_info in enumerate(self.column_query_info):
            column_name = column_info.column_name
            data_type = column_info.data_type_name
            data_type_length = column_info.data_length
            column_describe = column_info.column_describe
            # is_null = column_info.is_null
            # is_key = column_info.is_key
            # defalut_value = column_info.defalut_value

            if data_type_length:
                mid_str = '{} {}({})'.format(column_name, data_type, data_type_length)
            else:
                mid_str = '{} {}'.format(column_name, data_type)

            # # 是否主键
            # if not PRIMARY_KEY_str and is_key:
            #     PRIMARY_KEY_str = 'PRIMARY KEY ({}) DISABLE NOVALIDATE'.format(column_name)

            # 字段注释
            if column_describe:
                mid_str += " COMMENT '{}'".format(column_describe)

            if column_num < len(self.column_query_info) - 1:
                mid_str += ',\n'
            else:
                mid_str += '\n)\n'
                # if PRIMARY_KEY_str:
                #     mid_str += ',\n'
                #     mid_str += '{})\n'.format(PRIMARY_KEY_str)
                # else:
                #     mid_str += '\n)\n'

            sql_str += mid_str
        # 表注释
        if self.table_describe:
            sql_str += "COMMENT '{}'\n".format(self.table_describe)
        # 分区
        if partition_attr:
            if len(partition_attr.split(' ')) > 1:
                if '，' in partition_attr:
                    partition_attr = partition_attr.replace('，', ',')
                sql_str += 'PARTITIONED BY ({})\n'.format(partition_attr)
        # 分桶
        if cluster_attr:
            if int(cluster_nums) > 0:
                if '，' in cluster_attr:
                    cluster_attr = cluster_attr.replace('，', ',')
                cluster_str = 'CLUSTERED BY ({})'.format(cluster_attr)
                if cluster_sort_attr:
                    if '，' in cluster_sort_attr:
                        cluster_sort_attr = cluster_sort_attr.replace('，', ',')
                    cluster_str += 'SORTED BY ({})'.format(cluster_sort_attr)
                cluster_str += 'INTO num_buckets {}\n'.format(cluster_nums)
        # 结尾
        tail_sql = "ROW FORMAT DELIMITED FIELDS TERMINATED BY '{}'\n" \
                   "COLLECTION ITEMS TERMINATED BY '{}'\n" \
                   "MAP KEYS TERMINATED BY '{}'\n" \
                   "LINES TERMINATED BY '{}'\n" \
                   "STORED AS {}".format(fields_terimial, item_terimial, map_terminal, line_terimial, save_format)

        if save_path:
            tail_sql += "\nlocation '{}'".format(save_path)
        tail_sql += ';'

        # 修复分区
        if partition_attr:
            tail_sql += '\n\nMSCK REPAIR TABLE {}.{};'.format(self.db_name, self.table_name)

        return create_table_sql + '\n' + sql_str + tail_sql

    def read_mysql(self):
        storageengine = self.table_info.get('storageengine')
        charset = self.table_info.get('charset')

        create_table_sql = 'DROP TABLE IF EXISTS {};\n'.format(self.table_name)
        sql_str = 'CREATE TABLE IF NOT EXISTS {}(\n'.format(self.table_name)
        # 字段
        key_flag = False
        for column_num, column_info in enumerate(self.column_query_info):
            column_name = column_info.column_name
            data_type = column_info.data_type_name
            data_length = column_info.data_length
            column_describe = column_info.column_describe
            is_null = column_info.is_null
            is_key = column_info.is_key
            defalut_value = column_info.defalut_value

            if data_length:
                mid_str = '{} {}({}) '.format(column_name, data_type, data_length)
            else:
                mid_str = '{} {}'.format(column_name, data_type)

            # 主键
            if not key_flag and is_key:
                mid_str += ' primary key'
                key_flag = True
            # 非空
            if not is_null:
                mid_str += ' not null'

            # 默认值
            if defalut_value:
                mid_str += ' default {}'.format(defalut_value)
            # 注释
            if column_describe:
                mid_str += " COMMENT '{}'".format(column_describe)

            if column_num < len(self.column_query_info) - 1:
                mid_str += ',\n'
            else:
                mid_str += '\n)'

            sql_str += mid_str
        # 存储引擎与字符
        tail_sql = 'ENGINE={} DEFAULT CHARSET={};'.format(storageengine, charset)
        return create_table_sql + '\n' + sql_str + tail_sql


# mapping
class OperaMapping(object):
    @staticmethod
    def get(table_id, db_id=None):
        if db_id:
            query_info = MappingInfo.query.join(DimColumn, DimColumn.id == MappingInfo.column_id).\
                add_columns(MappingInfo.column_id, DimColumn.column_name, MappingInfo.target_db,
                            MappingInfo.target_table, MappingInfo.target_column).\
                filter(MappingInfo.db_id == db_id).filter(MappingInfo.table_id == table_id)
        else:
            query_info = MappingInfo.query.join(DimColumn, DimColumn.id == MappingInfo.column_id). \
                add_columns(MappingInfo.column_id, DimColumn.column_name, MappingInfo.target_db,
                            MappingInfo.target_table, MappingInfo.target_column). \
                filter(MappingInfo.table_id == table_id)
        table_info = query_info.all()
        if table_info:
            mapping_dict = dict()
            for data in table_info:
                if data.column_id in mapping_dict:
                    info = '{}.{}.{}'.format(data.target_db, data.target_table, data.target_column)
                    mapping_dict[data.column_id]['info'] += ';{}'.format(info)
                else:
                    mapping_dict[data.column_id] = {
                            'id': data.column_id,
                            'column_name': data.column_name,
                            'info': '{}.{}.{}'.format(data.target_db, data.target_table, data.target_column)
                        } if data.target_db else {
                        'id': data.column_id,
                        'column_name': data.column_name,
                        'info': None
                    }
            return list(mapping_dict.values())

    @staticmethod
    def post_signal(data):
        db_id = data.get('db_id')
        table_id = data.get('table_id')
        column_id = data.get('column_id')
        target_db = data.get('target_db')
        target_table = data.get('target_table')
        target_column = data.get('target_column')
        owner_id = data.get('owner_id')
        is_valid = True

        task = MappingInfo(db_id=db_id, table_id=table_id, column_id=column_id, target_db=target_db,
                           target_table=target_table, target_column=target_column, owner_id=owner_id, is_valid=is_valid)
        db.session.add(task)

    @staticmethod
    def read_mapping_info(column_id, target_column):
        table_info = MappingInfo.query.filter_by(column_id=column_id, target_column=target_column).first()
        return table_info

    def post(self, json_data):
        if isinstance(json_data, list):
            for data in json_data:
                put_data = self.read_mapping_info(column_id=int(data.get('column_id')),
                                                  target_column=data.get('target_column'))
                if put_data:
                    print('数据已存在')
                else:
                    self.post_signal(data=data)
        else:
            put_data = self.read_mapping_info(column_id=int(json_data.get('column_id')),
                                              target_column=json_data.get('target_column'))
            if put_data:
                print('数据已存在')
            else:
                self.post_signal(data=json_data)
        db.session.commit()
        return 'create success', 201

    @staticmethod
    def put_signal(put_data, data):
        put_data.id = put_data.id
        put_data.db_id = data.get('db_id')
        put_data.table_id = data.get('table_id')
        put_data.column_id = data.get('column_id')
        put_data.target_db = data.get('target_db')
        put_data.target_table = data.get('target_table')
        put_data.target_column = data.get('target_column')
        put_data.owner_id = data.get('owner_id')
        put_data.is_valid = put_data.is_valid

        db.session.commit()
        return 'update success', 204


# 用户信息
opera_user = OperaUser()
# product
opera_dim_product = OperaDimProduct()
# 数据库
opera_dim_db = OperaDimDb()
# 表
opera_db_table_relate = OperaDbTableRelate()
# 字段
opera_table_column_relate = OperaTableColumnRelate()
# 数据库驱动
opera_dim_db_driver_type = OperaDimDbDriverType()
# 字段标准数据类型
opera_dim_data_type = OperaDataType()
# 标准指标分类
opera_column_category = OperaColumnCategory()
# 标准指标
opera_dim_column = OperaDimColumn()
# post sql
opera_sql = OperaSql()
# mapping
opera_mapping = OperaMapping()
